import { createApp,onMounted } from 'vue'
import './style.css'
/* import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css' */
import store from './store'
import router from './router/index'
import App from './App.vue'
import './api/mock.js'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import api from './api/api.js'


const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.config.globalProperties.$api = api
store.commit('ADD_MENU',router)
app.use(router).use(store)
//app.use(ElementPlus)
const checkRouter = (path)=>{
    let hasCheck = router.getRoutes().filter(item => item.path == path).length
    if(hasCheck){
        return true
    }else{
        return false
    }
}
router.beforeEach((to,from,next)=>{
    store.commit('GET_TOKEN')
    const token = store.state.token
    if(!token && to.name !== 'login'){
        next({name:'login'})
    }else if(!checkRouter(to.path)){
        next({name:'home'})
    }else{
        next()
    }
})

app.mount('#app')


